package com.marketingexpert.controller.messagemgnt;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.marketingexpert.domain.Task;
import com.marketingexpert.domain.WeiboContent;
import com.marketingexpert.service.messagemgnt.TaskService;

public class EditorDraftController implements Controller {
	
	private TaskService taskService = null;
	
	private String successView = null;
	
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		response.setContentType("application/x-json;charset=GBK"); 
		response.setHeader("Pragma", "No-cache"); 
		response.setHeader("Cache-Control", "no-cache"); 
		response.setHeader("Cache-Control", "no-store"); 
		response.setDateHeader("Expires", 0);  
		PrintWriter out = response.getWriter();				
		String draftId = request.getParameter("draftId");
		Task task = getTaskService().queryTaskById(Integer.parseInt(draftId));
		
		WeiboContent wc = task.getWeiboContent();
		
		if(wc.getImagePath() != null) {
			request.getSession().setAttribute("savePath", wc.getImagePath());
			request.getSession().setAttribute("uploadImageName", wc.getUploadImageName());
		}
		
		JSONObject taskJson = JSONObject.fromObject(task);
		
		
		
		out.print(taskJson);
		return null;
	}

	public String getSuccessView() {
		return successView;
	}

	public void setSuccessView(String successView) {
		this.successView = successView;
	}

	public TaskService getTaskService() {
		return taskService;
	}

	public void setTaskService(TaskService taskService) {
		this.taskService = taskService;
	}
	
	

}
